<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>键盘事件</h1>
		<ul>
			<li>keydown</li>
			<li>keyup</li>
			<li>keypress</li>
			
		</ul>
		<input type="text" id="input1"/>
		<input type="text" id="input2"/>
		<script type="text/javascript">
			input1.onkeydown=function(e){
				console.log(e.key)
				console.log("按下"+e.keyCode)
				console.log(e)
				if(e.keyCode!=8&&e.keyCode<48||e.keyCode>57)
				{
					event.preventDefault()
				}
			}
			input1.onkeyup=function(e)
			{
				console.log("抬起"+e.keyCode)
				input2.value=e.keyCode
			}
			input1.onkeypress=function(e)
			{
				console.log("按了"+e.keyCode)
			}
		</script>
		
	</body>
</html>
